package yxy.cherry.battle.module.actor;

import yxy.apple.util.RandomUtility;
import yxy.cherry.battle.Pokemon;

/**
 * @ClassName Actor_神兽
 * @Author jingtao-zheng
 * @Date 2022/6/28 15:04
 * @Version 1.0
 **/
public class Actor_神兽 extends Actor {

    @Override
    public void doAct() {
        //神兽初始轮-战力高的先执行
        pokemonInitial();
    }

    @Override
    public boolean canAct() {
        return true;
    }

    private void pokemonInitial(){
        if(isTeamA()){
            Pokemon pokemonA = getContext().getTeamA().getPokemon();
            if(pokemonA!=null){
                pokemonA.doAct();
            }
            Pokemon pokemonB = getContext().getTeamB().getPokemon();
            if(pokemonB!=null){
                pokemonB.doAct();
            }
        }else{
            Pokemon pokemonB = getContext().getTeamB().getPokemon();
            if(pokemonB!=null){
                pokemonB.doAct();
            }
            Pokemon pokemonA = getContext().getTeamA().getPokemon();
            if(pokemonA!=null){
                pokemonA.doAct();
            }
        }
    }

    private boolean isTeamA(){
        double battlePowerA = this.context.getTeamA().getBattlePower();
        double battlePowerB = this.context.getTeamB().getBattlePower();
        // 战力优先，战力一致则随机优先
        if (battlePowerA == battlePowerB) {
            return RandomUtility.nextInt(0, 2) < 1;
        }
        return battlePowerA > battlePowerB;
    }

}
